package com.yinxin.wudasuanfa.huaweiod;

import java.util.*;

/**
 * @author yinxin
 * @version 1.0
 * @Description: 停车位：给定一个类似"10000100101"的字符串，1代表有车停着，0代表空车位，求在停车位停车与最近的车之间的最大距离
 * @date 2022/5/911:36
 */
public class Exercise7 {
    public static void main(String[] args) {
        String park = "10000100101";
        String[] split = park.split("");
        boolean flag =false;
        int tmp = 0;
        int maxvalue = 0;
        for (int i = 0; i < split.length; i++) {
            if("1".equals(split[i])){
                if(flag){
                    maxvalue=Math.max(maxvalue,Math.abs(i-tmp));
                }
                tmp=i;
                flag=true;
            }
        }
        System.out.println(maxvalue);
    }

}
